
//
// 120328 - AH - (Bergen Off. Bibliotek *) Created.
// 120729 - AH - (Midtun *) EMPTY_ARRAY.
//

package org.soekrat.server.io.db;

import javax.persistence.Id;

/**
 * <p>
 *   Meta data for 
 *   {@link DbFileData}.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC)
 */
public final class DbFile implements DbObject 
{
  private @Id Long id;
  
  private Long folderId=null;
  
  private Long ownerId=null;
  
  private String name=null;
  
  private String use=null;
  
  private String type=null;
  
  private boolean text=false;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   */
  public DbFile(){}
  
  /**
   * <p>
   *   Gets unique of key of the data.
   * </p>
   * @return Key value or {@code -1} if not assigned (not stored in database).
   */
  public long id(){ return id==null ? -1 : id; }
  
  /**
   * <p>
   *   Gets name given to data.
   * </p>
   * @return Name or {@code null} if has non.
   */
  public String name(){ return name; }
  
  /**
   * <p>
   *   Gets name given to data.
   * </p>
   * @return Name or {@code null} if has non.
   */
  public DbFile name(String name){ this.name=name; return this; }
  
  /**
   * <p>
   *   Gets the key of the folder this belong to. 
   * </p>
   * @return Key value or {@code -1} if not assigned.
   */
  public long folderId(){ return folderId==null ? -1 : folderId; }
  
  /**
   * <p>
   *   Sets the key of the folder {@code this} is in. 
   * </p>
   * @param id Key.
   * @return {@code this}.
   */
  public DbFile folderId(long id)
  {
    if (id<0)
    {
      throw new IllegalArgumentException("id<0 : "+id);
    }
    
    this.folderId=id;
    
    return this;
  }
  
  /**
   * <p>
   *   Gets the key of the owner of this. 
   * </p>
   * @return Key value or {@code -1} if not assigned.
   */
  public long ownerId(){ return ownerId==null ? -1 : ownerId; }
  
  /**
   * <p>
   *   Sets the key of the owner of {@code this}. 
   * </p>
   * @param id Key.
   * @return {@code this}.
   */
  public DbFile ownerId(long id)
  {
    if (id<0)
    {
      throw new IllegalArgumentException("id<0 : "+id);
    }
    
    this.ownerId=id;
    
    return this;
  }
  
  /**
   * <p>
   *   Gets the text that describes the use of the data,
   * </p>
   * @return Use description or {@code null} if not given.
   */
  public String use(){ return use; }
  
  /**
   * <p>
   *   Sets the text that describes the use of the data,
   * </p>
   * @param use Description or {@code null} or the empty string if to clear.
   * @return {@code this}.
   */
  public DbFile use(String use)
  {
    use=(use==null) ? "" : use.trim();
    this.use=(use.length()==0) ? null : use;
    return this;
  }
  
  /**
   * <p>
   *   Gets the text that describes the type of the data,
   * </p>
   * <p>
   *   Typical type value would be MIME type but can be custom.
   * </p>
   * @return Type or {@code null} if not given.
   */
  public String type(){ return type; }
  
  /**
   * <p>
   *   Sets the text that describes the type of the data,
   * </p>
   * <p>
   *   Typical type value would be MIME type but can be custom.
   * </p> 
   * @param use Type or {@code null} or the empty string if to clear.
   * @return {@code this}.
   */
  public DbFile type(String type)
  {
    type=(type==null) ? "" : type.trim();
    this.type=(type.length()==0) ? null : type;
    return this;
  }
  
  /**
   * <p>
   *   Tells if data is pure text.
   * </p>
   * @return {@code true} if is, {@code false} if is not.
   */
  public boolean text(){ return text; }
  
  /**
   * <p>
   *   Sets if data is pure text.
   * </p>
   * @param v {@code true} if is, {@code false} if is not.
   * @return  {@code this}.
   */
  public DbFile text(boolean v){ this.text=v; return this; }
  
  /**
   * <p>
   *   The empty array shared.
   * </p>
   */
  public static final DbFile[] EMPTY_ARRAY=new DbFile[0];
  
}
